
const mlis = document.querySelector('.menu-list > ul')
    userCenter()
    async function userCenter() {
        // 2-1. 请求数据
        const res = await pAjax({
          url: 'https://www.lemall.com/api/news/footerNews.html',
          data: {  },
          dataType: 'json'
        })
      
        // 2-3. 渲染页面
        var str = ''
        res.data.forEach(item => {
          str += `
            <li><a>${ item.name }</a></li>
          `
        })
        mlis.innerHTML = str
    }


    

function hotkeyfn(){
  const hotk = document.querySelector('.keywords')
    hotKeys()
    async function hotKeys() {
        // 2-1. 请求数据
        const res = await pAjax({
          url: 'https://www.lemall.com/api/searchKeyword.html',
          data: {  },
          dataType: 'json'
        })
      
        // 2-3. 渲染页面
        var str = ''
        res.data.forEach(item => {
          str += `
            <a>${ item }</a>
          `
        })
        hotk.innerHTML = str
      }
}

hotkeyfn()








    const leftMenu = document.querySelector('.leftMenu > ul')
    const lsMenu = document.querySelector('.listBox')

    secMenu()
    async function secMenu() {
        // 2-1. 请求数据
        const res = await pAjax({
          url: 'https://www.lemall.com/api/indexCate.html',
          data: {  },
          dataType: 'json'
        })
      
        // 2-3. 渲染页面
        var str = ''
        res.data.cateList.forEach(item => {
          str += `
          <li><a href="#">${item.name}</a>
          <i>></i>
          <div class="listBox">
              `
              
              item.childs.forEach(item => {
                str += `
              <dl>
                
                <dt>
                    <a href="">${item.name}</a>
                    <span>></span>
                </dt>

                `
                str += `     
                        <dd>`
                        
                    item.childs.forEach(item=>{
                        str+=`
                            <a href="">${item.name}</a>
                 
                    `
                    })
                    str+=`  </dd>
                    </dl>
                    `                            
              })
              str+=
              `                                                       
             
           
          </div>
      </li>
          `
        })
        
        leftMenu.innerHTML = str
      }



      
    const newGol = document.querySelector('.likeBox > ul')
   newGoods()
    async function newGoods() {
        // 2-1. 请求数据
        const res = await pAjax({
          url: 'https://www.lemall.com/api/indexFloor.html',
          data: {  },
          dataType: 'json'
        })
      
        // 2-3. 渲染页面
        var str = ''
        let skList = res.data.floorList.find(item => item.name === '新品上市')

        const skbox = document.querySelector('.likeBox > ul')


        skList.classList.forEach(item => {

            item.dataList.forEach(item => {

                str += `
                <li>
                <div class="pImg">
                    <a href="">
                        <img src="${item.product.masterImg}">
                    </a>
                </div>
                <div class="pInfo">
                    <div class="pName"><a href="">${item.product.name1}</a></div>
                    <div class="pPrice">
                       <i>
                        ¥${item.product.mallPcPrice}
                      </i>
                    </div>
                </div>
            </li>
                
                `
            })
            skbox.innerHTML = str
      })

    }


  // producList

    const producList = document.querySelector('.producList')
    producListFun()
    async function producListFun() {
      // 1. 请求数据
      const res = await pAjax({
        url: 'https://www.lemall.com/api/indexFloor.html',
        data: {  },
        dataType: 'json'
      })
    
      // 2. 渲染页面
      var str = ''
      for(let i = 0; i < res.data.floorList.length; i++){
        if(res.data.floorList[i].name === '新品上市') continue
        str += `
          <div>
              <div class="container pl-topic">
              <a href="">
                  <img src="${res.data.floorList[i].advImage}" dataset-url="${res.data.floorList[i].advLinkUrl}">
              </a>
          </div>
          <div class="container content-box">
              <div class="titBox">
                  <div class="titlab">
                      <span class="title">${res.data.floorList[i].name }</span>
                      `
                      res.data.floorList[i].patchList.forEach(item => {
                        str += `
                        <span class="link"><a>${item.title}</a></span>
                        `
                      })
                      str +=`                               
                  </div>
                  <a class="more">更多</a>
              </div>
              <div class="pl-goodslist">
                  <div class="leftg">
                      <img src="${res.data.floorList[i].masterImage}" alt="">
                  </div>
                  <div class="main">
                      <ul  class="intodetail">
                      `
                      res.data.floorList[i].classList.forEach(item => {
                        item.dataList.forEach(item => {
                          str += `
                          <li data-id="${item.product.id}">
                              <div class="p-img"><a><img src="${item.product.masterImg}" alt="" ></a></div>
                              <div class="p-name"><a>${item.product.name1}</a></div>
                              <div class="p-price">
                                  <span>¥</span>
                                  <span>${item.product.mallPcPrice}</span>
                              </div>
                          </li>
                          `
                        })
                      })
                      str +=
                      
                      `
                      </ul>
                  </div>
              </div>
              </div>
          </div>
        `
        // console.log(res);
      }
      producList.innerHTML = str
      const listBox = document.querySelectorAll('.intodetail')
      listBox.forEach(item => {
        item.addEventListener('click', e => {
          if(e.target.nodeName === 'LI'){
            const goodsId = e.target.dataset.id
            window.sessionStorage.setItem('goodsId', goodsId)
            console.log(goodsId);
            // window.location.href = '../views/detail.html'
          }
         
        }
        )
      })
}

// --------------------------------------------













// --------------------------------------------













  const recList = document.querySelector('.recom-list')
  recListFun()
    async function recListFun() {
        // 2-1. 请求数据
        const res = await pAjax({
          url: 'https://www.lemall.com/api/indexProducts.html',
          data: {  },
          dataType: 'json'
        })
      
        // 2-3. 渲染页面
      var str = ''
      res.data.products.forEach(item => {
        str += `
        <li>
        <div class="p-img"><a><img src="${item.masterImg}" alt="" ></a></div>
        <div class="p-name"><a>${item.name1}</a></div>
        <div class="p-price">
            <span>¥</span>
            <span>${item.mallPcPrice}</span>
        </div>
        <div class="${item.single ? 'list-goods-tip' : ''}">
            <span>${item.single ? '立减' : ''}</span>
        </div>
    </li>
        `
      })
      recList.innerHTML = str
         

    }




    const footerwraper = document.querySelector('.wraper > ul')
    footerFun()
    async function footerFun() {
        // 2-1. 请求数据
        const res = await pAjax({
          url: 'https://www.lemall.com/api/news/footerNews.html',
          dataType: 'json'
        })
      
        // 2-3. 渲染页面
      var str = ''
      res.data.forEach(item => {
        str += `
        <li>
            <dl>
                <dt>${item.name}</dt>
                    `
                    item.news.forEach( item => {
                      str +=`
                      <dd>
                          <i></i>
                           <a href="">${item.title}</a>
                      </dd>                     
                      `                   
                    })
                    str +=
                    `
            </dl>                       
        </li>
        `
      })
      footerwraper.innerHTML = str     

    }



    const bannerBox = document.querySelector('.imgBox')
    // bannerFun()
    async function bannerFun() {
        // 2-1. 请求数据
        const res = await pAjax({
          url: 'https://www.lemall.com/api/indexBanner.html',
          dataType: 'json'
        })
      
        // 2-3. 渲染页面
      var str = ''
      // console.log(item);
      // console.log(res.data.bannerList);

        res.data.bannerList.forEach(item => {
          // item.
      console.log(item);

            str += `
            <li>
            <a href=""><img src="${item.image}" alt="" style="width:1920px; height: 456px;"></a>        
            </li>
            `
        })
        bannerBox.innerHTML = str


    }


    


